<template>
  <div>
    <router-link tag='div' to='/' class="abs" v-show='showAbs'>
      <span class='iconfont abs-icon'>&#xe624;</span>
    </router-link>
    <div class="fixed" v-show='!showAbs' :style='opacityStyle'>
      <router-link to='/'>
        <div class="iconfont header-fixed-back">&#xe624;</div>
      </router-link>
      景点详情
    </div>
  </div>
</template>
<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      const top = document.documentElement.scrollTop
      if (top > 10) {
        this.showAbs = false
        var opacity = top / 220
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity }
      } else {
        this.showAbs = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}

</script>
<style lang='stylus' scoped>
@import '~styles/varibles.styl'

.abs {
  position: absolute;
  top: .2rem;
  left: .2rem;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 50%;
  padding: .15rem;
}

.abs-icon {
  color: #fff;
}

.fixed {
  position: fixed;
  z-index:99;
  top: 0;
  left: 0;
  width: 100%;
  background: $bgColor;
  height: $headerHeight;
  line-height: $headerHeight;
  color: #fff;
  text-align: center;
  font-size: .3rem;
}

.header-fixed-back {
  position: absolute;
  left: .2rem;
  color: #fff;
}

</style>
